package appname.example.com.testmvvm;

import android.app.job.JobParameters;
import android.app.job.JobService;
import android.os.AsyncTask;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.Log;

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class MyjobService extends JobService {

    private final String  TAG = MyjobService.class.getName();

    @Override
    public boolean onStartJob(JobParameters params) {
        new MyasyncTask().execute(params);
        return true;
    }

    @Override
    public boolean onStopJob(JobParameters params) {
        return true;
    }


    class MyasyncTask extends AsyncTask<JobParameters, Void, Void> {

        JobParameters parameter;

        @Override
        protected Void doInBackground(JobParameters... jobParameters) {

            // 问题1 为什么要有个这个？？
            parameter = jobParameters[0];

            try {
                Thread.sleep(10*1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            return null;
        }


        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);

            Log.e(TAG,"onPostExecute");
            jobFinished(parameter, false);
        }
    }
}
